#ifndef ABSTRACTCAMPAIGNITEMMODEL_H
#define ABSTRACTCAMPAIGNITEMMODEL_H



#include <QAbstractProxyModel>
#include <QMap>

typedef QPersistentModelIndex ProxyIndex;
typedef QPersistentModelIndex SourceIndex;

typedef QMap<ProxyIndex, SourceIndex> IndexMapBase;




class IndexMap : public IndexMapBase
{
public:

    void map(const ProxyIndex& proxy, const SourceIndex& source)
    {
        insert(proxy, source);
    }

    bool hasProxy(const ProxyIndex& proxy) const
    {
        return (keys().contains(proxy));
    }

    bool hasSource(const SourceIndex& source) const
    {
        return (values().contains(source));
    }

    QList<ProxyIndex> proxies() const
    {
        return keys();
    }

    QList<SourceIndex> sources() const
    {
        return values();
    }

    ProxyIndex proxyOf(const SourceIndex& source) const
    {
        if (!hasSource(source)) return ProxyIndex();
        return key(source);
    }

    SourceIndex sourceOf(const ProxyIndex& proxy) const
    {
        if (!hasProxy(proxy)) return SourceIndex();
        return value(proxy);
    }

};



class AbstractCampaignItemModel : public QAbstractProxyModel
{
    Q_OBJECT

public:





    AbstractCampaignItemModel(QObject *parent = 0);
    virtual void setSourceModel(QAbstractItemModel *sourceModel);


protected slots:

    virtual void remap() = 0;


};



#endif // ABSTRACTCAMPAIGNITEMMODEL_H


